<?php

/**
 * This is the model class for table "feedback".
 *
 * The followings are the available columns in table 'feedback':
 * @property integer $id
 * @property string $username
 * @property string $text
 * @property string $date
 * @property string $comment
 */
class Feedback extends CActiveRecord
{
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	public function tableName()
	{
		return 'feedback';
	}

	public function rules()
	{
		return array(
			array('username, text, date, comment', 'required'),
			array('username', 'length', 'max'=>50),
			array('id, username, text, date, comment', 'safe', 'on'=>'search'),
		);
	}

    private function isLive()
    {
        return $_SERVER['HTTP_HOST'] == 'valerchyck.hol.es';
    }

    public function getDbConnection()
    {
        if ($this->isLive())
            return Yii::app()->live;
        else
            return Yii::app()->db;
    }

	public function attributeLabels()
	{
		return array(
			'id' => 'Ид',
			'username' => 'Пользователь',
			'text' => 'Текст',
			'date' => 'Дата',
			'comment' => 'Комментарий',
		);
	}

	public function search()
	{
		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('username',$this->username,true);
		$criteria->compare('text',$this->text,true);
		$criteria->compare('date',$this->date,true);
		$criteria->compare('comment',$this->comment,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}